package com.tougutips.modules.user.followers.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.tougutips.modules.user.followers.entity.User;
import com.tougutips.modules.user.followers.service.FollowersService;
import com.tougutips.modules.user.followers.service.RedisFollowService;
import com.tougutips.modules.user.followers.service.UserService;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;

/**
 * @author:HuangYiF
 * @create: 2022-07-21 19:20
 * @Description: 关注和取关controller
 */
@RestController
@RequestMapping("/follow")
public class FollowerController {
    @Autowired
    UserService userService;

    @Autowired
    FollowersService followersService;

    @Autowired
    RedisFollowService redisFollowService;

    /**
     * 获取当前用户的粉丝列表或者关注列表
     * @return
     */
    @GetMapping("/getfollowers")
    public AjaxResult getfollowers(Long userId,String type){
        return AjaxResult.success(redisFollowService.getFollowersFromRedis(userId,type));
    }

    /**
     * 关注其他用户
     * @param
     * @param otherId
     * @return
     */
    @GetMapping("/followOther")
    public AjaxResult followOther(Long userId, Long otherId){
        int result = redisFollowService.followOrUnFollow2Redis(userId,otherId);
        if(result == 1){
            return AjaxResult.success("已关注~");
        }else if(result == 0){
            return AjaxResult.success("已取关~");
        }
            return AjaxResult.error("用户不存在！不能关注");
    }

}
